[assembly:
        System.Web.UI.WebResource("BM.Tools.WebControls.MForm.Resources.dictionary.dictionaryen.js",
                "application/x-javascript")]
[assembly:
        System.Web.UI.WebResource("BM.Tools.WebControls.MForm.Resources.dictionary.dictionarypl.js",
                "application/x-javascript")]
[assembly:
        System.Web.UI.WebResource("BM.Tools.WebControls.MForm.Resources.dictionary.dictionaryro.js",
                "application/x-javascript")]

namespace BM.Tools.WebControls.MForm
{
    using System.Collections.Generic;
    using System.Globalization;
    using System.Web;
    using System.Web.UI;
    
    using BM.Tools.WebControls.MForm.Controls;    
    using BM.Tools.WebControls.MForm.ScriptReferences;

    /// <summary>
    /// A class that helps the <see cref="Root" /> control with registering scripts.
    /// </summary>
    public class RootScriptHelper
    {        
        /// <summary>
        /// Initializes a new instance of the <see cref="RootScriptHelper"/> class. 
        /// </summary>
        /// <param name="root">
        /// The root control.
        /// </param>
        public RootScriptHelper(Root root)
        {
            Root = root;
        }

        /// <summary>
        /// Gets the control on which the the helper works.
        /// </summary>
        /// <value>
        /// The root control.
        /// </value>
        public Root Root
        {
            get;
            private set;
        }        

        /// <summary>
        /// Adds all resources and scripts associated with the root control.
        /// </summary>
        public void RegisterScripts()
        {
            ScriptIncluder.IncludeResources(Root);
            ScriptManager sm = ScriptManager.GetCurrent(Root.Page);
            if (sm == null)
            {
                return;
            }

            ScriptReference sr =
                    new ScriptReference(
                            "BM.Tools.WebControls.MForm.Resources.dictionary.dictionary" + Root.PageLanguage + ".js",
                            "BM.Tools.WebControls.MForm");
            sm.Scripts.Add(sr);                       
            sm.RegisterScriptControl(Root);
            sm.RegisterScriptDescriptors(Root);
        }

        /// <summary>
        /// Implements the method from interface <see cref="IScriptControl" />.
        /// </summary>
        /// <returns>
        /// the enumeration of <see cref="ScriptDescriptor" /> obejcts
        /// </returns>
        public IEnumerable<ScriptDescriptor> GetScriptDescriptors()
        {
            var descriptor = new ScriptControlDescriptor("MForm", Root.UniqueID);
            descriptor.AddProperty("imagesPath", HttpContext.Current.Request.ApplicationPath + Root.CommonImagesPath);
            descriptor.AddProperty("mode", Root.Mode.ToString().ToLower(CultureInfo.InvariantCulture));            
            yield return descriptor;            
        }
    }
}